<?php
    ob_start();


    define('ABSOLUTE_SERVER_REMOTE_ADDR','../../../admin/');
    define('ABSOLUTE_SERVER_DOCUMENT_ROOT','../../../admin/');

    if(file_exists('../../../definitions.inc.php')) include_once('../../../definitions.inc.php');
    include(ABSOLUTE_SERVER_DOCUMENT_ROOT.'session.inc');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'funct.inc');   
   
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'functs.inc');
    require_once('adm_product_link.inc');
    include ABSOLUTE_SERVER_DOCUMENT_ROOT.'color_style.php';

    require_once('../../../plugins/i18n/classI18N.inc.php');
    require_once('../../../classDB.inc.php');
    require_once('../../../plugins/url/classURL.inc.php');
    require_once('../../../plugins/users/classUsersService.inc.php');
    require_once('../../../plugins/session/classSession.inc.php');
    require_once('../../../plugins/article/classArticleService.inc.php');
    require_once('../../../plugins/product/classPriceExport.inc.php');
    require_once('../../../plugins/product/classProductService.inc.php');
    require_once('../../../plugins/template/classTemplate.inc.php');
    require_once('../../../definitions.inc.php');
    include '../../'.LANGUAGE; //admin

    //set language (e-shop)
    $_i18n = new classI18N();
    $language = $_i18n->getActual('../../../');
    if($language!=-1 and $language!='') require $language;

    $_DB = new classDB();
    if (!$_DB->open()){echo OPEN_DB_ERR; break;}

    if(!GetAdminID($ID)){echo LOGIN_ERR; exit;}
    if(!Right_Check(4)){header('Location:'.ABSOLUTE_SERVER_DOCUMENT_ROOT.'error.php'); exit;}
?>
<html>

	

<head>
	<?php echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">'; ?>
	<style  type="text/css"><!--
		table{
            border-bottom-color: black;
            border-top-color: black;
            border-left-color: black;
            border-right-color: black;
            border-collapse: collapse;
            font-size: 10px;
            font-family:  verdana;
        }
        form {margin-top:0pt; margin-bottom:0px;}
        img {margin-top:0pt; margin-bottom:0px;}
        body{
            margin-left:0pt;
            margin-right:0pt;
            margin-top:0pt;
            margin-bottom:0pt;
            font-family:  verdana;
            font-size: 10px;
        }
        textarea{
        	border: 0;
            background-color: white;
            margin-left:0pt;
            margin-right:0pt;
            margin-top:0pt;
            margin-bottom:0pt;
            font-family:  verdana;
            font-size: 10px;
        }
        input {
            border: 1px solid black;
            cursor: pointer;
            background-color: white;
            font-size: 10px;
            margin-left: 0px;
            padding-left: 0px;
            list-style-type: none;
            font-family:  Verdana;
        }
        a {
		  	text-decoration: none; 
		  	font-weight: normal; 
		  	color:black; 
		  	font-size:10px;
		}
		a:hover {
		  	text-decoration: underline; 
			font-weight: normal; 
			color:#808080; 
			font-size:10px;
		}
    --></style>

    <?php
        print "
            <script language=\"JavaScript\">
                <!--
                    function OpenPage(id, count){
                        var ComletPageName= \"".ABSOLUTE_SERVER_DOCUMENT_ROOT."show_product_detail.php\" + \"?ID=\" + id + \"&amp;Count=\" + count;
                        window.close(\"ShopBasketProductDetail\");
                        window.open(ComletPageName,\"ShopBasketProductDetail\",\"width=700px,height=300px,location=no,directories=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes\");
                    }
                //-->
            </script>
        ";
    ?>

</head>

<?php
	print "<body bgcolor=\"".Background_Color."\">";

		
	$New_Address_List	= $_REQUEST['New_Address_List'];
	$Category_ID 		= $_REQUEST['Category_ID'];
	$Insert_Product_ID 	= $_REQUEST['Insert_Product_ID'];
	$Address_List		= $_REQUEST['Address_List'];
	$New_Email_Text		= $_REQUEST['New_Email_Text'];
	$New_Email_Text_Down= $_REQUEST['New_Email_Text_Down'];
	
	
	
do
{
  	//-----------------------------------------------------------------------------------------------
  	//nacitanie cookie a vytvorenie premennych
	if(isset($_SESSION[PRODUCT_LINK_COOKIE]))
		$Cookie_Value	= $_SESSION[PRODUCT_LINK_COOKIE];
	else
		$Cookie_Value	= "";
	
	//pri prvom nacitanie resetuje cookie a nacita default udaje
	if($_REQUEST['Reset_Cookie']=="YES"){
	  	$Cookie_Value	= "";
		$Email_Text		= GetDefaultMailText($ID);
		$EMail_Text_Down= GetDefaultMailTextDown($ID);
	}
	else{
		$Arr_Session	= explode("&-&",$Cookie_Value);
		$Products_List	= $Arr_Session[0];
		$Address_List	= $Arr_Session[1];
		$Email_Text		= $Arr_Session[2];
		$EMail_Text_Down= $Arr_Session[3];
	}
  	//-----------------------------------------------------------------------------------------------
  	
	//-----------------------------------------------------------------------------------------------
	//zmena text e-mailu
    $Send_Mail      = $_REQUEST['Send_Mail'];
    $Email_Subject  = $_REQUEST['Mail_Subject'];
    $Email_Sender   = $_REQUEST['Mail_AddressOfSender'];

	if($Send_Mail=="YES"){
	  	if($Address_List!=""){
			SendMail($Products_List,$Address_List,$Email_Text,$EMail_Text_Down,$Email_Subject,$Email_Sender);
			print ('<script type="text/javascript">alert("'.PL_EMAIL_V_PORIADKU_ODOSLANY.'");</script>');
			setcookie(PRODUCT_LINK_COOKIE,"");
			//break;
		}
		else{
			print  "<script language=\"JavaScript\">
		                <!--
		                        window.alert(\"".PL_NIE_SU_ZADANE_ZIADNE_EMAIL_ADRESY."\");
		                //-->
		            </script>";
		}
		
	}
	//-----------------------------------------------------------------------------------------------
	
	//-----------------------------------------------------------------------------------------------
	//zmena text e-mailu
	if($New_Email_Text!="") $Email_Text = $New_Email_Text;
	//-----------------------------------------------------------------------------------------------	
	
	//-----------------------------------------------------------------------------------------------
	//zmena adries
	if($New_Address_List!="") $Address_List = CheckAddressList($New_Address_List);
	//-----------------------------------------------------------------------------------------------
	
	//-----------------------------------------------------------------------------------------------
	//zmena paty
	if($New_Email_Text_Down!="") $EMail_Text_Down = $New_Email_Text_Down;
	//-----------------------------------------------------------------------------------------------
    
	//-----------------------------------------------------------------------------------------------
	//pridanie produktu
	if($Insert_Product_ID!="")
		$Products_List = Insert_Product_To_Cookie($Products_List, $Insert_Product_ID);
	//-----------------------------------------------------------------------------------------------

	//-----------------------------------------------------------------------------------------------
	//odstranenie produktu
	if($_REQUEST['Delete_Product_ID']!="")
		$Products_List = Delete_Product_From_Cookie($Products_List, $_REQUEST['Delete_Product_ID']);
	//-----------------------------------------------------------------------------------------------        
	
	//-----------------------------------------------------------------------------------------------
	//NADPIS
	print "<center><h4 style=\"margin-top:0pt; margin-bottom:0pt;\">".PL_VYBRANE_POLOZKY."</h4></center>";
	//-----------------------------------------------------------------------------------------------	
	
	//-----------------------------------------------------------------------------------------------
	//zobrazenie zoznamu adries
	Adm_Update_Address_List($Address_List);
	//-----------------------------------------------------------------------------------------------
	
	//-----------------------------------------------------------------------------------------------
	//text emailu
	Adm_Show_EMail_Text($Email_Text);
	if($_REQUEST['Text_Save_To_DB']=="YES") SetDefaultMailText($ID,$Email_Text);
	//-----------------------------------------------------------------------------------------------	
	
	//-----------------------------------------------------------------------------------------------
	//zoznam produktov
	Adm_Show_Products_From_Cookie($Products_List, ABSOLUTE_SERVER_REMOTE_ADDR);
	//-----------------------------------------------------------------------------------------------
	
	//-----------------------------------------------------------------------------------------------
	//text paty emailu
	Adm_Show_EMail_Text_Down($EMail_Text_Down);
	if($_REQUEST['Text_Down_Save_To_DB']=="YES") SetDefaultMailTextDown($ID,$EMail_Text_Down);
	//-----------------------------------------------------------------------------------------------	
	
	//-----------------------------------------------------------------------------------------------
	//ulozenie cookie
	$_SESSION[PRODUCT_LINK_COOKIE] = $Products_List."&-&".$Address_List."&-&".$Email_Text."&-&".$EMail_Text_Down;
	//-----------------------------------------------------------------------------------------------
	
	print "<br /><br />";
	Adm_Show_Send_Mail_Button();
	
	print "<br /><br />";

    mysql_close();
}
while(false)
?>


</body>
</html>